package jane.mvc.engine;

import jane.mvc.exceptions.ControllerNotFoundException;

import java.io.File;
import java.util.ArrayList;
import java.util.Hashtable;

public class AppDescriptor
{

	public String getHomeController() throws ControllerNotFoundException
	{
		// In this case, the default route is
		// mvc.controllers.HomeController::Index
		if (!configClassNames.contains("mvc.config.RoutesConfig"))
		{
			String defaultController = "mvc.controllers.HomeController";
			boolean hasHomeController = false;

			for (String classname : controllerClassNames)
			{
				if (classname.equals(defaultController))
				{
					hasHomeController = true;
					break;
				}
			}

			if (hasHomeController)
			{
				return defaultController;
			} else
			{
				throw new ControllerNotFoundException(
						String.format(
								"Default controller %s could not be found in the application",
								defaultController));
			}

		} else
		{
			return null;

		}

	}

	public File getJarFile()
	{
		return jarFile;
	}

	public ArrayList<String> getModelClassNames()
	{
		return modelClassNames;
	}

	public ArrayList<String> getControllerClassNames()
	{
		return controllerClassNames;
	}

	private File jarFile;
	private ArrayList<String> modelClassNames;
	private ArrayList<String> controllerClassNames;
	private ArrayList<String> janeViewsFiles;
	private ArrayList<String> configClassNames;

	private Hashtable<String, JaneMVCMethod> methodsByWebname;

	public AppDescriptor(File jarFile, ArrayList<String> controllerClassNames,
			ArrayList<String> modelClassNames,
			ArrayList<String> janeViewsFiles,
			ArrayList<String> configClassName,
			Hashtable<String, JaneMVCMethod> methodsByWebname)
	{
		this.jarFile = jarFile;
		this.modelClassNames = modelClassNames;
		this.controllerClassNames = controllerClassNames;
		this.janeViewsFiles = janeViewsFiles;
		this.configClassNames = configClassName;
		this.methodsByWebname = methodsByWebname;

	}

	public ArrayList<String> getJaneViewsFiles()
	{
		return janeViewsFiles;
	}

	public Hashtable<String, JaneMVCMethod> getMethodsByWebname()
	{
		return methodsByWebname;
	}

	public void setMethodsByWebname(
			Hashtable<String, JaneMVCMethod> methodsByWebname)
	{
		this.methodsByWebname = methodsByWebname;
	}

}
